package com.shangcheng.server.controller;

import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.SmsCouponHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 根据优惠券id，使用状态，订单编号分页获取领取记录
 */
@RestController
@RequestMapping("couponHistory")
public class SmsCouponHistoryController {
    @Autowired
    private SmsCouponHistoryService smsCouponHistoryService;

    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     *
     * @param couponId
     * @param orderSn
     * @param pageNum
     * @param pageSize
     * @param useStatus
     * @return
     */
    @GetMapping("list")
    @Cacheable(value = "CouponHistoryList", key = "'CouponHistory_'+#pageNum+'_'+#pageSize")
    public Result findAllCouponHistory(@RequestParam(required = false) Integer couponId,
                                       @RequestParam(required = false) String orderSn,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(required = false) Integer useStatus) {
        PageResult pr = smsCouponHistoryService.list(couponId, orderSn, pageNum, pageSize, useStatus);
        return new Result(200, pr, "");

    }
}
